PostgreSQL

class PostgreSQL(url: String, username: String, password: String, options: Driver.Pool.Options = Driver.Pool.Options()) : IPostgresSQL

PostgreSQL class provides mechanisms to interact with a PostgreSQL database. It implements Driver, Driver.Pool, and Driver.Transactional interfaces, offering functionalities such as connection pooling, executing queries, fetching data, and handling transactions.

The URL scheme designator can be either postgresql:// or postgres://. Each of the URL parts is optional.

postgresql:// postgresql://localhost postgresql://localhost:5433 postgresql://localhost/mydb

Parameters

url

The URL of the PostgreSQL database to connect to.

username

The username used for authentication.

password

The password used for authentication.

options

Optional pool configuration, defaulting to Driver.Pool.Options.

Constructors

Link copied to clipboard
constructor(url: String, username: String, password: String, options: Driver.Pool.Options = Driver.Pool.Options())

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Tx(connection: Connection) : Transaction

Represents a transactional context for executing SQL operations with commit and rollback capabilities.

Functions

Link copied to clipboard
open suspend override fun begin(): Result<Transaction>
Link copied to clipboard
open suspend override fun close(): Result<Unit>
Link copied to clipboard
open suspend override fun execute(statement: Statement): Result<Long>
open suspend override fun execute(sql: String): Result<Long>
Link copied to clipboard
open suspend fun <T> fetchAll(sql: String, rowMapper: RowMapper<T>): Result<List<T>>
open suspend override fun fetchAll(statement: Statement): Result<ResultSet>
open suspend override fun fetchAll(sql: String): Result<ResultSet>
open suspend override fun <T> fetchAll(statement: Statement, rowMapper: RowMapper<T>): Result<List<T>>
Link copied to clipboard
open suspend override fun listen(channel: String, f: (Notification) -> Unit)

Listens for notifications from a specified PostgreSQL channel.

open suspend override fun listen(channels: List<String>, f: (Notification) -> Unit)

Listens for notifications from the specified PostgreSQL channels.

Link copied to clipboard
open suspend override fun migrate(path: String): Result<Unit>
Link copied to clipboard
open suspend override fun notify(channel: String, value: String)

Sends a notification to a specific PostgreSQL channel with the given value.

Link copied to clipboard
open override fun poolIdleSize(): Int
Link copied to clipboard
open override fun poolSize(): Int
Link copied to clipboard
open suspend fun <T> transaction(f: suspend Transaction.() -> T): T
Link copied to clipboard
open fun validateChannelName(channel: String)

Validates the name of a PostgreSQL channel to ensure it adheres to the naming rules.